package com.dragon.modules.yuegou.service.impl.member;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.member.TemplateFormEntity;
import com.dragon.modules.yuegou.mapper.member.TemplateFormMapper;
import com.dragon.modules.yuegou.model.member.TemplateForm;
import com.dragon.modules.yuegou.query.member.TemplateFormQuery;
import com.dragon.modules.yuegou.service.member.TemplateFormService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 会员模板表单信息 服务实现
 *
 * @author pbuilder generated
 * @date 2021-10-26 20:50:05
 * @version 2.0
 */
@Service("memTemplateFormService")
public class TemplateFormServiceImpl
		extends ServiceImpl<TemplateFormMapper, TemplateFormEntity>
		implements TemplateFormService {

	@Override
	public void saveTemplateFormList(String templateSetId,List<TemplateForm> templateForms) {		
		if(StringUtils.isNotBlank(templateSetId)) {
			TemplateFormQuery query = new TemplateFormQuery();
			query.setTemplateSetId(templateSetId);
			remove(query.toQueryWrapper());
		}
		for(TemplateForm templateForm : templateForms) {
			save(templateForm);
		}	
	}

	
	@Override
	public List<TemplateForm> getTemplateFormsList(String templateSetId) {
		TemplateFormQuery query = new TemplateFormQuery();
		query.setTemplateSetId(templateSetId);
		return list(query.toQueryWrapper()).stream().map(TemplateForm::new).collect(Collectors.toList());
	}

}